package com.lkc.service.impl;

import com.lkc.annotation.LogMethod;
import com.lkc.bean.Comments;
import com.lkc.mapper.CommentsDao;
import com.lkc.service.CommentsService;
import com.lkc.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentsServiceImpl implements CommentsService {

    @Autowired
    private CommentsDao commentsDao;

    @Override
    @LogMethod(serviceName = "评论服务", recordParam = true, recordReturn = true)
    public Comments add(Comments comments) {
        commentsDao.add(comments);
        return commentsDao.one(comments.getCommentId());
    }

    @Override
    @LogMethod(serviceName = "评论服务", recordParam = true, recordReturn = true)
    public int del(Integer commentId) {
        return commentsDao.del(commentId);
    }

    @Override
    @LogMethod(serviceName = "评论服务", recordParam = true, recordReturn = true)
    public Comments edit(Comments comments) {
        commentsDao.edit(comments);
        return commentsDao.one(comments.getCommentId());
    }

    @Override
    @LogMethod(serviceName = "评论服务", recordParam = true, recordReturn = true)
    public Comments one(Integer commentId) {
        return commentsDao.one(commentId);
    }

    @Override
    @LogMethod(serviceName = "评论服务", recordParam = true, recordReturn = false)
    public void page(Page page, Comments comments) {
        int count = commentsDao.pageCount(comments);
        Object data = commentsDao.page(page, comments);
        page.setCount(count);
        page.setData(data);
    }

    @Override
    @LogMethod(serviceName = "评论服务", recordParam = true, recordReturn = false)
    public List<Comments> findByProductId(Integer productId) {
        return commentsDao.findByProductId(productId);
    }

    // 添加查询所有评论的方法实现
    @Override
    @LogMethod(serviceName = "评论服务", recordParam = true, recordReturn = false)
    public List<Comments> all(Comments comments) {
        return commentsDao.all(comments);
    }
}
